package com.solo.servlet;

import com.solo.entity.Article;
import com.solo.entity.Category;
import com.solo.entity.User;
import com.solo.service.ArticleService;
import com.solo.service.CategoryService;
import com.solo.service.UserService;
import com.solo.service.impl.ArticleServiceImpl;
import com.solo.service.impl.CategoryServiceImpl;
import com.solo.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "IndexServlet", value = "/index")
public class IndexServlet extends HttpServlet {
    private ArticleService articleService;
    private UserService userService;
    private CategoryService categoryService;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        userService = new UserServiceImpl();
        List<User> userList = userService.selectAllUser();
        request.setAttribute("userList", userList);
        categoryService = new CategoryServiceImpl();
        List<Category> listCategory = categoryService.selectAllCategory();
        request.setAttribute("categoryList", listCategory);
        articleService = new ArticleServiceImpl();
        List<Article> listArticle = articleService.selectAllArticle();
        request.setAttribute("articleList", listArticle);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
        dispatcher.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("--------------------");
    }
}